/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Shared Source License
* for DSL Editor PowerToy. A copy of the license can be found in the License.htm file
* at the root of this distribution. If you can not locate the Shared Source License
* for DSL Editor PowerToy, please obtain a copy from: http://www.codeplex.com/dsltreegrideditor/Project/License.aspx.
* By using this source code in any fashion, you are agreeing to be bound by
* the terms of the Shared Source License for DSL Editor PowerToy.
*
* You must not remove this notice, or any other, from this software.
*
* **********************************************************************************/
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Text;

using Microsoft.VisualStudio.Modeling.Diagrams;

namespace DslEditorPowerToy.Languages.EditorConfiguration
{
    public class HeadStoneShapeGeometry : RoundedRectangleShapeGeometry
    {
        #region Public Methods
        protected override GraphicsPath GetPath(RectangleD boundingBox)
        {
            GraphicsPath basePath = base.GetPath(boundingBox);
            double radius = this.Radius;

            //Check if somethign to do
            if (radius <= (double)0)
                return basePath;

            //The existing path consists of 8 sections, 4 for the sides and 4 for the corners,
            //starting at top left and going clockwise
            //we want to create a duplicate path that removes the 2 bottom corners, and extends the side, and bottom to square teh corners again.
            basePath.Reset();

            //Create a bounding rectangle for a full circle
            RectangleD rectangle = new RectangleD();
            rectangle.Width = 2 * radius;
            rectangle.Height = 2 * radius;

            basePath.StartFigure();

            //Top Left corner arc
            rectangle.X = boundingBox.Left;
            rectangle.Y = boundingBox.Top;
            basePath.AddArc((float)rectangle.X, (float)rectangle.Y,
                (float)rectangle.Width, (float)rectangle.Height, 180f, 90f);
            //Top side line
            basePath.AddLine((float)(boundingBox.Left + radius), (float)boundingBox.Top,
                (float)(boundingBox.Right - radius), (float)boundingBox.Top);
            //Top Right corner arc
            rectangle.X = boundingBox.Right - (2 * radius);
            basePath.AddArc((float)rectangle.X, (float)rectangle.Y,
                (float)rectangle.Width, (float)rectangle.Height, 270f, 90f);
            //Right side line
            basePath.AddLine((float)boundingBox.Right, (float)(boundingBox.Top + radius),
                (float)boundingBox.Right, (float)boundingBox.Bottom);
            //Bottom side line
            basePath.AddLine((float)boundingBox.Right, (float)boundingBox.Bottom,
                (float)boundingBox.Left, (float)boundingBox.Bottom);
            //Left side line
            basePath.AddLine((float)boundingBox.Left, (float)boundingBox.Bottom,
                (float)boundingBox.Left, (float)(boundingBox.Top + radius));

            basePath.CloseFigure();

            return basePath;
        }
        #endregion
    }

    public class HeadStoneShapeAreaField : AreaField
    {
        #region Constructors
        public HeadStoneShapeAreaField(string fieldName)
            : base(fieldName, 0f, 0f, 0f, 0f)
        {
        }
        #endregion

        #region Public Methods
        public override AreaFieldCornerRadius GetCornerRadius(ShapeElement parentShape)
        {
            //Prune corner radius
            AreaFieldCornerRadius cornerRadius = base.GetCornerRadius(parentShape);
            NodeShape shape = parentShape as NodeShape;
            cornerRadius.SouthWestCornerRadius = 0f;
            cornerRadius.SouthEastCornerRadius = 0f;

            return cornerRadius;
        }
        #endregion
    }

}
